namespace CloudNinja.Metering.Providers.Configuration.BlobBandwidth
{
    using System.Configuration;

    public class BlobBandwithStorageAccountsCollection : ConfigurationElementCollection
    {
        public override ConfigurationElementCollectionType CollectionType
        {
            get
            {
                return ConfigurationElementCollectionType.AddRemoveClearMap;
            }
        }

        public BlobBandwidthCollectionElement this[int index]
        {
            get
            {
                return this.BaseGet(index) as BlobBandwidthCollectionElement;
            }

            set
            {
                if (this.BaseGet(index) != null)
                {
                    this.BaseRemoveAt(index);
                }

                this.BaseAdd(index, value);
            }
        }

        public BlobBandwidthCollectionElement Get(string name)
        {
            return (BlobBandwidthCollectionElement)this.BaseGet(name);
        }

        public void Add(BlobBandwidthCollectionElement element)
        {
            this.BaseAdd(element);
        }

        public void Clear()
        {
            this.BaseClear();
        }

        public void Remove(BlobBandwidthCollectionElement element)
        {
            this.BaseRemove(element.Name);
        }

        public void Remove(string name)
        {
            this.BaseRemove(name);
        }

        public void RemoveAt(int index)
        {
            this.BaseRemoveAt(index);
        }
        
        protected override ConfigurationElement CreateNewElement()
        {
            return new BlobBandwidthCollectionElement();
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((BlobBandwidthCollectionElement)element).Name;
        }
    }
}